﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Models;

namespace Web
{
    public partial class Share : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.Header.Title == "首页")
            {
                Page.Title = "ChingeDesign 尚器设计 | Make a Chinge";
            }
            else {
                Page.Title = Page.Header.Title + " - ChingeDesign 尚器设计 | Make a Chinge";
            }
            
            
            CheckDirection();
            ContactBindData();
        }

        public void CheckDirection()
        {
            //添加tab标签默认选中项
            Dictionary<string, string> urlItem = new Dictionary<string, string>();
            urlItem.Add("index.aspx", "home");
            urlItem.Add("about.aspx", "about");
            urlItem.Add("news.aspx", "news");
            urlItem.Add("newsreading.aspx", "news");
            urlItem.Add("works.aspx", "works");
            urlItem.Add("workreading.aspx", "works");
            urlItem.Add("service.aspx", "service");
            urlItem.Add("servicereading.aspx", "service");
            urlItem.Add("career.aspx", "career");

            string currentUrl = HttpContext.Current.Request.Url.LocalPath.ToLower().Substring(1).ToString();
            string currentLi ="";
            try
            {
                currentUrl = currentUrl.Substring(currentUrl.LastIndexOf("/") + 1);
                currentLi = urlItem[currentUrl].ToString();
            }
            catch
            {
                return;
            }
            
            switch (currentLi)
            {
                case "home":
                    homeli.Attributes.Add("class", "current");
                    break;
                case "about":
                    aboutli.Attributes.Add("class", "current");
                    break;
                case "news":
                    newsli.Attributes.Add("class", "current");
                    break;
                case "works":
                    workli.Attributes.Add("class", "current");
                    break;
                case "service":
                    serviceli.Attributes.Add("class", "current");
                    break;
                case "career":
                    careerli.Attributes.Add("class", "current");
                    break;
            }
            urlItem.Clear();
        }

        public void ContactBindData()
        {
            List<ContactInfo> contactlist = ContactInfoLogic.GetContactInfo();
            if (contactlist == null)
            {
                contactlist = new List<ContactInfo>();
                contactlist.Add(new ContactInfo());
            }
            contactReperter.DataSource = contactlist;
            contactReperter.DataBind();
        }
    }
}
